//
//  RecipesViewController.swift
//  FridgeSolo
//
//  Created by LiuXing on 2017/6/10.
//  Copyright © 2017年 kumi.com. All rights reserved.
//

let avtarTableViewCellIdentifier = "AvatarTableViewCell"
let profileTableViewCellIdentifier = "ProfileTableViewCell"

import UIKit

class ProfileViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        title = "Profile"
        view.backgroundColor = UIColor.white
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.edges.equalTo(view)
        }
        
        logoutButton.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.bottom.equalTo(logoutButton)
            make.left.equalTo(logoutButton.snp.left).offset(10)
            make.right.equalTo(logoutButton.snp.right).offset(-10)
            make.height.equalTo(0.5)
        }
        tableView.tableFooterView = logoutButton
    }
    
    lazy var tableView: UITableView = {
        let tableView = UITableView.init(frame: CGRect.zero, style: UITableViewStyle.plain)
        tableView.separatorStyle = .none
        tableView.register(UINib.init(nibName: "AvatarTableViewCell", bundle: nil), forCellReuseIdentifier: avtarTableViewCellIdentifier)
        tableView.register(UINib.init(nibName: "ProfileTableViewCell", bundle: nil), forCellReuseIdentifier: profileTableViewCellIdentifier)
        tableView.dataSource = self
        tableView.delegate = self
        return tableView
    }()
    
    private lazy var logoutButton: UIButton = {
        let btn = UIButton.init(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 50))
        btn.setTitle("Logout", for: .normal)
        btn.setTitleColor(UIColor.lightGray, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 20)
        return btn
    }()
    
    private lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.lightGray
        return view
    }()
    
}

extension ProfileViewController: UITableViewDataSource, UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == 0 {
            return 92
        } else {
            return 55
        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 8
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            let cell = tableView.dequeueReusableCell(withIdentifier: avtarTableViewCellIdentifier, for: indexPath) as! AvatarTableViewCell
            return cell
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: profileTableViewCellIdentifier, for: indexPath) as! ProfileTableViewCell
            return cell
        }
    }
}

